package com.htt.base_library.base

import android.app.ActivityManager
import android.content.Context
import android.os.Process
import androidx.multidex.MultiDex
import androidx.multidex.MultiDexApplication
import com.hjq.toast.ToastUtils
import com.htt.base_library.constant.BaseConstant
import com.htt.base_library.util.logTagDebug
import com.orhanobut.logger.Logger
import com.test.library_base.BuildConfig

open class BaseApplication : MultiDexApplication() {

    override fun onCreate() {
        super.onCreate()
        //主进程
        // 初始化 Toast 框架
        ToastUtils.init(this);
        Logger.addLogAdapter(BaseConstant.LOG_TAG.logTagDebug(BuildConfig.DEBUG))
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(base)
    }

    /**
     * 获取当前进程名
     */
    private fun getCurrentProcessName(): String? {
        val pid = Process.myPid()
        var processName = ""
        val manager =
            applicationContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        for (process in manager.runningAppProcesses) {
            if (process.pid == pid) {
                processName = process.processName
            }
        }
        return processName
    }
}